using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace IGGCore
{
    public class News : IComparable
    {
        public string Link { get; set; }

        private string m_content = "";
        private string m_title = "";
        private string m_date = "";
        private string m_provider = "";
        private List<TeamIdentification> m_teams = new List<TeamIdentification>();
        private List<string> m_players = new List<string>();
        private string m_imageURL = "";

        private int m_headlineRatio = 0;

        public int HeadlineRatio
        {
            get { return m_headlineRatio; }
            set { m_headlineRatio = value; }
        }

        public string Content
        {
            get { return m_content; }
            set { m_content = value; }
        }

        public string ImageURL
        {
            get { return m_imageURL; }
            set { m_imageURL = value; }
        }

        public List<TeamIdentification> Teams
        {
            get { return m_teams; }
            set { m_teams = value; }
        }

        public List<string> Players
        {
            get { return m_players; }
            set { m_players = value; }
        }
        
        public string Title
        {
            get { return m_title; }
            set { m_title = value; }
        }
        
        public string Date
        {
            get { return m_date; }
            set { m_date = value; }
        }

        public DateTime DateObject
        {
            // Wed, 22 Jan 2014 15:26:08 EST
            // Tue, 28 Jan 2014 14:04:34 EST
            // 2014-02-07T20:22:58Z
            // FEB 13, 11:30a ET
            
            get 
            {
                DateTime result = new DateTime(1970, 1, 1);
                var formatStrings = new string[] { "MMM d, HH:mmt ET", "ddd, d MMM yyyy HH:mm:ss z", "yyyy-MM-ddTHH:mm:ssZ", "ddd, d MMM yyyy HH:mm:ss EST", "ddd, d MMM yyyy hh:mm:ss EST", "MM/dd/yyyy hh:mm:ss tt", "yyyy-MM-dd hh:mm:ss" };
                try
                {
                    result = DateTime.Parse(Date);
                }
                catch
                {
                    string tempdate = Date.Replace("PST", "+2").ToUpper();

                    if (DateTime.TryParseExact(tempdate, formatStrings, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out result))
                    {
                        //success
                        //you can use date
                    }
                    else
                    {
                        //fail
                    }
                }
                return result;
            }
        }
        
        public string Provider
        {
            get { return m_provider; }
            set { m_provider = value; }
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            News b = obj as News;
            if (this.HeadlineRatio > b.HeadlineRatio)
            {
                return -1;
            }
            else if (this.HeadlineRatio < b.HeadlineRatio)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        #endregion
    }
}
